import request from '@/utils/request';

// 获取权限列表
export function getTreePermissions() {
  return request({
    url: '/user/permission/getTreePermissions',
    method: 'get'
  })
}

// 根据角色ID查询权限信息列表
export function getPermissionByRoleId(roleId) {
  return request({
    url: `/user/permission/getPermissionByRoleId/${roleId}`,
    method: 'get'
  })
}

// 保存角色与权限的关系
export function saveRolePermissionRel(data) {
  return request({
    url: `/user/permission/saveRolePermissionRel`,
    method: 'POST',
    data
  })
}

// 删除节点
export function deletePermissionNode(data) {
  return request({
    url: `/user/permission/deletePermissionNode`,
    method: 'POST',
    data
  })
}

// 新增节点
export function createNode(data) {
  return request({
    url: `/user/permission/createNode`,
    method: 'POST',
    data
  })
}

// 新增父节点
export function createParentNode(data) {
  return request({
    url: `/user/permission/createParentNode`,
    method: 'POST',
    data
  })
}

// 根据权限ID获取权限信息
export function getPermissionById(permissionId) {
  return request({
    url: `/user/permission/getPermissionById/${permissionId}`,
    method: 'get'
  })
}

// 编辑节点
export function editNode(data) {
  return request({
    url: `/user/permission/editNode`,
    method: 'POST',
    data
  })
}

// 获取用户的权限代码列表
export function getUserPermissionCodeList(userId) {
  return request({
    url: `/user/permission/getUserPermissionCodeList`,
    method: 'GET',
    params: {
      userId
    }
  })
}
